package com.hhh.corejava.code04_循环结构;

import java.util.Scanner;

/**
 * @autor 黄焕晖
 * @date 2025年10月21日17:10
 **/
public class Test16_打印菱形 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入菱形的行数：");
        int rows = sc.nextInt();
        if (rows%2==0){
            System.out.println("请输入奇数行");

        }else {
            int rows1 = rows/2+1;
            //上半部分
            for (int i = 1; i <= rows1; i++) {
                for (int j = 1; j <= rows1 - i; j++) {
                    System.out.print(" ");
                }
                for (int k = 1; k <= i; k++) {
                    System.out.print("* ");
                }
                System.out.println();
            }
            //下半部分
            for (int i = rows1 - 1; i >= 1; i--) {
                for (int j = 1;j<=rows1 - i; j++) {
                    System.out.print(" ");
                }
                for (int k = 1; k <= i; k++) {
                    System.out.print("* ");
                }
                System.out.println();
            }
        }
    }
}
